package top.dark.product.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.dark.product.entity.CategoryEntity;
import top.dark.product.service.CategoryService;
import top.dark.product.service.IndexService;
import top.dark.product.vo.Catelog2Vo;

import java.util.List;
import java.util.Map;

/**
 * Author: Darkn
 * description:
 * Create Time: 2021/3/3 18:20
 */
@Controller
public class IndexController {

    @Autowired
    private IndexService indexService;
    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/", "/index.html"})
    public String indexPage(Model model) {
        // 拿到三级分类菜单所有数据
        List<CategoryEntity> categorys = categoryService.getLevel1Categorys();
        model.addAttribute("categorys", categorys);
        return "index";
    }

    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<Long, List<Catelog2Vo>> getCatelogJson(){
        Map<Long, List<Catelog2Vo>> catelogJson = categoryService.getCatelogsFromDb();
                //categoryService.getCatelogJsonFromDbWithRedisLock();
        return catelogJson;
    }

}
